#include <boost/serialization/map.hpp>
#include <boost/serialization/string.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <fstream>

using namespace std;

map<string, map<string, int> > n_map;

int to_int(const string& s){
  istringstream iss(s);
  int r;
  iss >> r;
  return r;
}

void split(const string& s, char c, vector<string>& v){
  int i = 0;
  int j = s.find(c);
  while(j != string::npos){
    string ss = s.substr(i,j-i);
    v.push_back(ss);
    i = j+1;
    j = s.find(c,i);
    if(j == string::npos)
      v.push_back(s.substr(i,s.length()-i));
  }
}

void print(const vector<string>& v){
  for(vector<string>::const_iterator i = v.begin();
      i != v.end();
      i++){
    cout << endl << *i;
  }
}

int main(int argc, char** argv){
  string s;
  while(getline(cin,s)){
    istringstream iss(s);
    string uid;
    string rest;
    iss >> uid;
    iss >> rest;

    if(n_map.find(uid) == n_map.end()){
      n_map.insert(make_pair(uid, map<string,int>()));
      cout << endl << "added user " << uid;
    }

    map<string, int> & uid_map = n_map[uid];

    vector<string> n_weights;
    split(rest, ',', n_weights);
    for(vector<string>::iterator i = n_weights.begin(); i != n_weights.end(); i++){
      string ss = *i;
      vector<string> n_w;
      split(ss,':',n_w);
      if(n_w.size() == 0){
	string n_id = ss;
	if(uid_map.find(n_id) == uid_map.end())
	  uid_map.insert(make_pair(n_id,0));
	uid_map[n_id] += 1;
	//cout << endl << "added neighbor " << n_id << " of " << uid << " weight : " << 1;
      }
      else if(n_w.size() == 2){
	string n_id = n_w[0];
	if(uid_map.find(n_id) == uid_map.end())
	  uid_map.insert(make_pair(n_id,0));
	uid_map[n_id] += to_int(n_w[1]);
	//cout << endl << "added neighbor " << n_id << " of " << uid << " weight : " << n_w[1];
      }
    }
  }

  cout << endl << "writing map ... ";

  ofstream ofs("nw.bin", ios::binary);
  boost::archive::binary_oarchive oa(ofs);
  oa << n_map;
  
  return 0;
}
